package classics;

import java.util.Scanner;

//循环三要素 循环变量初始化 存在循环条件（布尔表达式，用于控制循环是否继续，条件为真循环继续，为假，循环结束） 循环变量会更新
//经典循环语句练习题
public class LoopExercise {
    public static void main(String[] args) {
 /*      //九九乘法表
        for (int i = 1; i <10 ; i++) {
            for (int j = 1; j <=i; j++) {
                System.out.print(j+"*"+i+"="+i*j+"\t");
            }
            System.out.println();
        }


        //求水仙花数 考察循环和算术运算符/和%
        for (int i =100; i <1000; i++) {
            int a = i/100;
            int b = (i/10)%10;
            int c = i%10;
            if (a*a*a+b*b*b+c*c*c==i){
                System.out.print(i+"\t");
            }
        }
        System.out.println();


        //计算阶乘 阶乘 考察的是循环和扩展赋值运算符（自带强转功能）
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您要计算的整数：");
        int n = scanner.nextInt();
        int result = 1;
        for (int i =1; i <=n; i++) {
            result*=i;
        }
        System.out.println(n+"的阶乘是："+result);

*/
        //打印斐波那契数列
        Scanner scanner2 = new Scanner(System.in);
        System.out.println("请输入您需要展示的斐波那契数列的项数：");
        int o = scanner2.nextInt();
        int a = 0,b=1;
        System.out.print(a+" "+b+" ");
        for (int i =2; i <o; i++) {
            int c = a+b;
            System.out.print(c+" ");
            a=b;
            b=c;
        }

/*
        //猜数字 循环变量初始值操作和循环变量更新操作是一样的，所以考察了do while以及变量的作用域。
        int m =(int) (Math.random()*1000+1);
        Scanner scanner1 = new Scanner(System.in);
        int guess;
        do {
            System.out.println("猜：");
            guess = scanner1.nextInt();
            if (guess>n){
                System.out.println("大了");
            }else {
                System.out.println("小了");
            }
        }while(guess!=m);
        System.out.println("猜对了。");
*/
    }
}
